﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using MyBasicLib.Collections.Generic;

namespace MyBasicLib.PerformanceTest
{
    class CollectionsTest
    {
        SimpleCache<int, int> cache = new SimpleCache<int, int>();
        ReaderWriterCache<int, int> readerWriterCache = new ReaderWriterCache<int, int>();
        List<int> list = new List<int>();
        HashSet<int> hashSet = new HashSet<int>();

        public void SimpleCacheTestInsert(int count)
        {
            int i = 0;
            //MyBasicLib.Diagnostics.CodeTimer.Time("SimpleCacheTestInsert", count, () => cache.FetchOrCreateItem[i++]= 0);
        }
        public void SimpleCacheTestLookup(int count)
        {
            int i = 0;
            MyBasicLib.Diagnostics.CodeTimer.Time("SimpleCacheTestLookup", count, () => cache.FetchOrCreateItem(i++, a => 0));
        }
        public void ReaderWriterCacheTestInsert(int count)
        {
            int i = 0;
           // MyBasicLib.Diagnostics.CodeTimer.Time("ReaderWriterCacheTestInsert", count, () => readerWriterCache.Add(i++, 0));
        }
        public void ReaderWriterCacheTestLookup(int count)
        {
            int i = 0;
            MyBasicLib.Diagnostics.CodeTimer.Time("ReaderWriterCacheTestLookup", count, () => readerWriterCache.FetchOrCreateItem(i++, a => 0));
        }
        public void ListCacheTestInsert(int count)
        {
            int i = 0;
            MyBasicLib.Diagnostics.CodeTimer.Time("ListCacheTestInsert", count, () => list.Add(i++));
        }
        public void ListCacheTestLookup(int count)
        {
            int i = 0;
            MyBasicLib.Diagnostics.CodeTimer.Time("ListCacheTestLookup", count, () => list.BinarySearch(i++));
        }
        public void HashSetCacheTestInsert(int count)
        {
            int i = 0;
            MyBasicLib.Diagnostics.CodeTimer.Time("HashSetCacheTestInsert", count, () => hashSet.Add(i++));
        }
        public void HashSetCacheTestLookup(int count)
        {
            int i = 0;
            MyBasicLib.Diagnostics.CodeTimer.Time("HashSetCacheTestLookup", count, () => hashSet.Contains(i++));
        }
    }
}
